
package ua.trasferta.task22;

public class Field
{
	public int[][] data;
	public boolean[][] painted;
	public boolean inverted = false;

	public void invert()
	{
		for (int i = 0; i < this.data.length; ++i)
		{
			for (int j = 0; j < this.data[0].length; ++j)
			{
				this.data[i][j] = 1 - this.data[i][j];
			}
		}
		this.inverted = !this.inverted;
	}

	/**
	 * @param x row index
	 * @param y column index
	 * @return horizontal point quantity lenght
	 */
	public int getHorizontalLength(int x, int y)
	{
		for (int i = y + 1; i < this.data[x].length; i++)
		{
			if (this.data[x][i] != 1)
			{
				return i - y;
			}
		}
		return this.data[x].length - y;
	}

	/**
	 * @param x row index
	 * @param y column index
	 * @return vertical point quantity lenght
	 */
	public int getVerticalLength(int x, int y)
	{
		for (int i = x + 1; i < this.data[y].length; i++)
		{
			if (this.data[y][i] != 1)
			{
				return i - x;
			}
		}
		return this.data[y].length - x;
	}
}
